<template>
  <el-form-item :label="label" :required="required">
    <el-switch
      v-model="boolValue"
      :active-value="activeValue"
      :inactive-value="inactiveValue"
      :active-text="activeText"
      :inactive-text="inactiveText"
      :disabled="disabled"
      @change="handleChange"
    />
  </el-form-item>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'

export default defineComponent({
  name: 'BoolControl',
  props: {
    modelValue: {
      type: [Boolean, String, Number],
      required: true
    },
    label: {
      type: String,
      default: ''
    },
    required: {
      type: Boolean,
      default: false
    },
    activeValue: {
      type: [Boolean, String, Number],
      default: true
    },
    inactiveValue: {
      type: [Boolean, String, Number],
      default: false
    },
    activeText: {
      type: String,
      default: '是'
    },
    inactiveText: {
      type: String,
      default: '否'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  emits: ['update:modelValue'],
  setup(props, { emit }) {
    const boolValue = computed({
      get: () => props.modelValue,
      set: (val) => emit('update:modelValue', val)
    })

    const handleChange = (value: any) => {
      emit('update:modelValue', value)
    }

    return {
      boolValue,
      handleChange
    }
  }
})
</script>